﻿#include "dialog.h"
#include "ui_dialog.h"

Dialog::Dialog(QDialog *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);
    // t2必须在connect()函数调用之前创建
    t2 = new TestThread2();
    connect(t2,&TestThread2::TestSignal,this,&Dialog::DisplayMsg);
    connect(this,&Dialog::ResetSignal,t2,&TestThread2::ResetSlot);
}

Dialog::~Dialog()
{
    delete ui;
}

void Dialog::on_pushButton_clicked()
{
    t2->start(); // 执行子线程
}


void Dialog::on_pushButton_3_clicked()
{
    emit ResetSignal();
}

void Dialog::DisplayMsg(int num)
{
    ui->label->setText(QString::number(num));
}

void Dialog::on_pushButton_2_clicked()
{
    t2->terminate(); // 结束线程
}

